<?
session_start();
$_SESSION['lastPage'] = "Albums";

require("../mysql.config.inc");
$mysqli = new mysqli($host,$username,$password,$db);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>A Photo Gallery</title>
	<link rel="stylesheet" type="text/css" href="stylesheets/styles.css"/>
</head>

<body>
	<div id="content">
	<div id="nav">
		<dl class="menu">
			<dd><a href="index.php">Home</a></dd>
			<dd class = "active"><a href="albums.php">Albums</a></dd>
			<dd><a href="photos.php">All Photos</a></dd>
			<dd><a href="admin.php">Administration</a></dd>
		</dl>
	</div>
	
	<h2>Albums</h2>
	
	<?
		if(isset($_GET['albumId'])){
			$id= $_GET['albumId'];
			$result=$mysqli->query("SELECT*  FROM Albums WHERE aid=$id");
			while($dropList = $result->fetch_assoc()){
				print "<h4>".$dropList['Title']."</h4>";
			}
		}
	?>
	
	<div id="albumList" class="grid">
		<p>Select an Album to see:<br/><br/>
			<?
			$albumList = $mysqli->query('SELECT* FROM Albums ORDER BY Title');
			
			while($dropList = $albumList->fetch_assoc()){
				print("<a href=\"http://info230.cs.cornell.edu/users/aballantine/www/p3/albums.php?albumId=".$dropList['aid']."\">".$dropList['Title']."</a><br/>");
			}
			?>	
		</p>
	</div>
		
	
		
	<div id="photoLayout" class="grid">
	<?
		if(isset($_GET['albumId'])){
			$id= $_GET['albumId'];
			$result=$mysqli->query("SELECT* FROM Photos NATURAL JOIN AlbumIn WHERE aid=$id ORDER BY sequence");
			while($photos = $result->fetch_assoc()){
				print("<a href=\"http://info230.cs.cornell.edu/users/aballantine/www/p3/
				viewphoto.php?pid=".$photos['pid']."&aid=".$photos['aid']."\" class=\"thumb\">");
				print("<img src=\"thumbs/".$photos['Link']."\" title=\"".$photos['Caption']."\"/></a>\n");
			}
		}
		$mysqli->close();
	?>
	
	<div id="extra">
	
	</div>
	</div>
	</div>
</body>
</html>